package com.walker.taskscheduling.config;

import com.banggood.sp.dispatcher.builder.TaskSourceBuilder;
import com.banggood.sp.dispatcher.core.TaskSource;
import com.banggood.sp.dispatcher.factory.TaskSourceBuilderFactory;
import com.walker.taskscheduling.listener.FirstTaskSourceListener;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author RR
 * @date 2024/2/19 23:35
 */
@Configuration
public class TaskSourceConfiguration {

    @Resource
    private FirstTaskSourceListener firstTaskSourceListener;

    @Bean
    public TaskSource firstTaskSource(TaskSourceBuilderFactory taskSourceBuilderFactory) {
        TaskSourceBuilder produce = taskSourceBuilderFactory.produce();
        TaskSource firstTaskSource = produce.setJobName("firstTask").setListener(firstTaskSourceListener).setIsBatch(false).build();
        return firstTaskSource;
    }
}
